using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.DirectX;

namespace Noein.Interpolator
{
    public delegate float Interpolate(List<float> keys, int previousKey, float u);

    public class Interpolator
    {
        public static float Linear(List<float> keys, int previousKey, float u)
        {
            return (keys[previousKey + 1] - keys[previousKey]) * u + keys[previousKey];
        }

        //public static float Hermite(List<float> keys, int previousKey, float u)
        //{
        //    return 0f;
        //}

        //public static float CatmullRom(List<float> keys, int previousKey, float u)
        //{

        //    float p0 = (previousKey - 1) >= 0 ? keys[previousKey - 1] : keys[previousKey] - 0.5f;
        //    float p1 = keys[previousKey];
        //    float p2 = keys[previousKey + 1];
        //    float p3 = ((previousKey + 2) < keys.Count) ? keys[previousKey + 2] : keys[previousKey + 1] + 0.5f;

        //    float test =  0.5f * ((2f * p1) + (-p0 + p2) * u + 
        //        (2 * p0 - 5 * p1 + 4 * p2 - p3) * u * u +
        //        (-p0 + 3 * p1- 3 * p2 + p3) * u * u * u);

        //    return test;
        //}
    }
    
    /*public abstract class Interpolator
    {
        private SortedDictionary<float, float> keyValuePairs;

        public Interpolator(SortedDictionary<float, float>rawKeyValuePairs)
        {
            keyValuePairs = rawKeyValuePairs;
            Normalize();
        }

        /// <summary>
        /// Estimate value of a function f(u)
        /// </summary>
        /// <param name="u">value between 0 and 1</param>
        /// <returns></returns>
        public abstract float Interpolate(float u);

        private void Normalize()
        {
            

            Dictionary<float, float>.KeyCollection keys = keyValuePairs.Keys;
            foreach(float key in keys)
            {
            }

            float first = keys.Keys.;
            float last = keys.Keys[keys.Count - 1];
        }
    }*/
}
